package com.controller;

import com.github.pagehelper.PageInfo;
import com.javabean.Orders;
import com.service.OrdersManagerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Resource
    OrdersManagerService ordersManagerServiceImpl;

    @RequestMapping("/findAll")
    public ModelAndView findAll(ModelAndView mv, @RequestParam(value = "page",required = false,defaultValue = "1") int page, @RequestParam(value = "limit",required = false,defaultValue = "5") int limit,String key,String value){
        ArrayList<Orders> all = ordersManagerServiceImpl.findAll(page, limit,key,value);
        PageInfo<Orders> pageInfo=new PageInfo<>(all);
        mv.addObject("pageInfo",pageInfo);

        //为了使查询结束数据依旧显示在页面 需要回填
        mv.addObject("select",key);
        mv.addObject("selectValue",value);

        mv.setViewName("/orders/orders-list");
        return mv;
    }
    @RequestMapping("/findById")
    public String findById(HttpServletRequest request, int id){
        Orders orders = ordersManagerServiceImpl.showOrders(id);
        request.setAttribute("order",orders);
        return "/orders/orders-show";
    }



}
